package FirstExampe.last;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {
	private String _name;
	private Vector<Rental> _rentals = new Vector<>();

	public Customer(String _name) {
		super();
		this._name = _name;
	}

	public String getName() {
		return _name;
	}

	public void addRentals(Rental rental) {
		this._rentals.addElement(rental);
	}

	public String statment() {
		Enumeration<Rental> rentals = _rentals.elements();
		String result = "Rental Record for" + getName() + "\n";
		while (rentals.hasMoreElements()) {
			Rental each = rentals.nextElement();
			result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.amount()) + "\n";
		}
		result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
		result += "You earned " + String.valueOf(getTotalFrequent()) + " frequent renter points";
		return result;
	}
	
	private double getTotalCharge(){
		double result = 0; 
		Enumeration<Rental> rentals = _rentals.elements();
		while(rentals.hasMoreElements()){
			result += rentals.nextElement().amount();
		}
		return result;
	}
	
	private int getTotalFrequent(){
		int result = 0; 
		Enumeration<Rental> rentals = _rentals.elements();
		while(rentals.hasMoreElements()){
			result += rentals.nextElement().frequent();
		}
		return result;
	}
}
